﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;
using MySchool;

namespace MyKTV.wmb
{
    public partial class Form5 : Form
    {
        DBHelper dBHelper = new DBHelper();
        DataSet ds = new DataSet();
        public Form5()
        {
            InitializeComponent();
        }

        private void Form5_Load(object sender, EventArgs e)
        {

            dBHelper.OpenConnection();
            string sql = "select * from song_type";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, dBHelper.Connection);
            adapter.Fill(ds, "song_type");
            comboBox1.DataSource = ds.Tables["song_type"];
            comboBox1.ValueMember = "songtype_id";
            comboBox1.DisplayMember = "songtype_name";
            
            string sql1 = "select * from singer_info";
            SqlDataAdapter adapter1 = new SqlDataAdapter(sql1, dBHelper.Connection);
            adapter1.Fill(ds,"singer_info");
            comboBox2.DataSource = ds.Tables["singer_info"];
            comboBox2.ValueMember = "singer_id";
            comboBox2.DisplayMember = "singer_name";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
        }
    
        private void textBoxEx4_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string wxt1;
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Multiselect = true;
            openFileDialog.Title = "请选择文件";
            openFileDialog.Filter = "音乐(*.mp3)|*.mp3";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog.FileName != "")
                {
                    wxt1 = openFileDialog.FileName;
                    textBoxEx4.Text = wxt1.Substring(openFileDialog.FileName.LastIndexOf("//") + 1);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //第一步 打开链接
            dBHelper.OpenConnection();
            //第二步 链接歌曲
            string sql = "insert song_info (song_name,song_ab,song_word_count,songtype_id,singer_id,song_url,song_play_count) values(N'"+this.textBoxEx1.Text+"', N'"+this.textBoxEx2.Text+ "', N'" +this.textBoxEx3.Text +
              "',N'" + this.comboBox1.SelectedValue.ToString() + "',N'" + this.comboBox2.SelectedValue.ToString() + "', N'" + this.textBoxEx4.Text+ "', N'" + this.textBoxEx5.Text + "'); ";
            //new一个SqlCommand对象
            SqlCommand sqlCommand = new SqlCommand(sql,dBHelper.Connection);
            //执行增加操作
            int count = sqlCommand.ExecuteNonQuery();
            //判断count是否为0，如果大于0那么增加成功，如果小于0那么增加失败
            if (count > 0)
            {
                MessageBox.Show("增加成功");
            }
            else {
                MessageBox.Show("增加失败");
            }
            //关闭数据库
            dBHelper.CloseConnection();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }
    }
}
